package game.script;

import hscript.Interp;
import game.worlds.GameRole;

/**
 * 角色脚本支持
 */
class RoleScript {
	public var role:GameRole;

	@:noCompletion private var script:Script;

	/**
	 * 读取角色脚本变量
	 * @param key 
	 * @return Dynamic
	 */
	public function getVariables(key:String):Dynamic {
		return this.script.variables.get(key);
	}

	/**
	 * 设置角色脚本变量
	 * @param key 
	 * @param value 
	 */
	public function setVariables(key:String, value:Dynamic):Void {
		this.script.variables.set(key, value);
	}

	/**
	 * 构造角色脚本实现
	 * @param role 
	 * @param source 
	 */
	public function new(role:GameRole, fileName:String, source:String = null):Void {
		this.role = role;
		this.script = new Script(this, fileName, source);
		this.onInit();
		if (this.script.functions.exists("onInit")) {
			this.script.functions.get("onInit").call();
		}
	}

	public function onInit():Void {}
}
